package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hm
 * @version 1.0
 * @date Created in 2024/7/10 15:06
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @PutMapping("/{status}")
    @ApiOperation("更改店铺营业状态")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("更改店铺营业状态:{}",status);
        stringRedisTemplate.opsForValue().set(StatusConstant.SHOP_STATUS_KEY,status.toString());
        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getShopStatus(){
        Integer s =Integer.valueOf(stringRedisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS_KEY));
        log.info("获取到店铺的营业状态为：{}",s == 1 ? "营业中" : "打烊中");
        return Result.success( s);
    }
}
